﻿@* @model ZR.CodeGenerator.Model.GenerateDto; *@
@{
    var genTable = Model.GenTable;
    var isHasEnableStateField=genTable.Options.IsHasEnableStateField;
    var subTableOptions = Model.SubTableOptions;
    var genOptions = Model.GenOptions;
    var replaceDto = Model.ReplaceDto;
}

using Infrastructure.Extensions;
using @(genOptions.ModelsNamespace).Enums;
@if (genTable.TplCategory.Contains("subNav") && genTable.SubTable != null)
{
    @:using @(subTableOptions.ModelsNamespace).@(subTableOptions.SubNamespace);
}

namespace @(genOptions.ModelsNamespace).@(genOptions.SubNamespace).Entity
{
    /// <summary>
    /// @(genTable.FunctionName)
    /// </summary>
    public class @(genTable.EntityClassName)Base
    {
@foreach(var item in genTable.Columns)
{
        @:/// <summary>
        @:/// @(item.FieldDesc)
        @:/// </summary>
    if (item.IsPk || item.IsIncrement)
    {
        @:[SugarColumn(IsPrimaryKey = @(item.IsPk.ToString().ToLower()), IsIdentity = @(item.IsIncrement.ToString().ToLower())@(item.CsharpField.ToLower() != item.ColumnName.ToLower() ? ", ColumnName = \"@item.ColumnName\"" : ""))]
    }
    else if (item.CsharpField.ToLower() != item.ColumnName.ToLower())
    {
        @:[SugarColumn(ColumnName = "@item.ColumnName")]
    }
    else if (item.AutoFillType == 1 && item.CsharpType == "DateTime")
    {
        @:[SugarColumn(InsertServerTime = true, IsOnlyIgnoreUpdate = true)]
    }
    else if (item.AutoFillType == 2 && item.CsharpType == "DateTime")
    {
        @:[SugarColumn(UpdateServerTime = true, IsOnlyIgnoreInsert = true)]
    }
    else if (item.AutoFillType == 3 && item.CsharpType == "DateTime")
    {
        @:[SugarColumn(InsertServerTime = true, UpdateServerTime = true)]
    }
    else if (item.AutoFillType == 1)
    {
        @:[SugarColumn(IsOnlyIgnoreUpdate = true)]
    }
    if(isHasEnableStateField && item.CsharpField==genTable.Options.StateCodeField)
    {
        @:public @(item.CsharpType)@item.DbRequiredStr @item.CsharpField { get; set; } = DataStateEnum.Enabled.ToEnumCode();
    }
    else
    {
        @:public @(item.CsharpType)@item.DbRequiredStr @item.CsharpField { get; set; }@((item.ColumnIsRequired && item.CsharpType=="string")?"= string.Empty;":"")
    }
@:
}
    @if (genTable.TplCategory == "tree")
    {
        @:[SugarColumn(IsIgnore = true)]
        @:public List<@(genTable.EntityClassName)> Children { get; set;}
    }
    @if ((genTable.TplCategory == "subNav" || genTable.TplCategory == "sub") && genTable.SubTable != null)
    {
        @:[Navigate(NavigateType.OneToOne, nameof(@(replaceDto.PKName)))] //自定义关系映射
        @:public @(genTable.SubTable.EntityClassName) @(genTable.SubTable.EntityClassName)Nav { get; set; }
    }
    @if (genTable.TplCategory == "subNavMore" && genTable.SubTable != null)
    {
        @:[Navigate(NavigateType.OneToMany, nameof(@(genTable.SubTable.EntityClassName).@(genTable.SubTableFkName)), nameof(@(replaceDto.PKName)))] //自定义关系映射
        @:public List<@(genTable.SubTable.EntityClassName)>
        @:@(genTable.SubTable.EntityClassName)Nav { get; set; }
    }
    }
}